﻿using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Prospectus
{
    public static class InputManager
    {
        static KeyboardState currentKeyState, previousKeyState;
        static MouseState currentMouseState, previousMouseState;

        public static Vector2 MousePosition = Vector2.Zero;

        public static void Update()
        {
            previousKeyState = currentKeyState;
            currentKeyState = Keyboard.GetState();

            previousMouseState = currentMouseState;
            currentMouseState = Mouse.GetState();

            MousePosition = new Vector2(currentMouseState.X, currentMouseState.Y);
        }

        public static bool IsKeyDown(Keys key)
        {
            return currentKeyState.IsKeyDown(key);
        }

        public static bool IsKeyPress(Keys key)
        {
            return currentKeyState.IsKeyDown(key) &&
                previousKeyState.IsKeyUp(key);
        }

        public static bool IsCurrentKeyDown(Keys key)
        {
            return currentKeyState.IsKeyDown(key);
        }

        public static bool IsPreviousKeyDown(Keys key)
        {
            return previousKeyState.IsKeyDown(key);
        }

        public static bool IsMouseLeftDown()
        {
            return currentMouseState.LeftButton == ButtonState.Pressed;
        }

        public static bool IsMouseLeftClick()
        {
            return currentMouseState.LeftButton == ButtonState.Pressed &&
                previousMouseState.LeftButton == ButtonState.Released;
        }

        public static bool IsMouseRightDown()
        {
            return currentMouseState.RightButton == ButtonState.Pressed;
        }
            
        public static bool IsMouseRightClick()
        {
            return currentMouseState.RightButton == ButtonState.Pressed &&
                previousMouseState.RightButton == ButtonState.Released;
        }

        public static bool IsMouseWheelUp()
        {
            return currentMouseState.ScrollWheelValue > previousMouseState.ScrollWheelValue;
        }

        public static bool IsMouseWheelDown()
        {
            return currentMouseState.ScrollWheelValue < previousMouseState.ScrollWheelValue;
        }
    }
}
